//===============================================================================
// Microsoft patterns & practices
// Guidance Explorer Offline Client
//===============================================================================
// Copyright  Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================



using System;
using System.Windows.Forms;

namespace GuidanceExplorer.Controls
{
    public partial class InputBox : Form
    {
        public delegate bool ValidateInput(string userInput);
        ValidateInput _validator = null;

        public InputBox(string title, string message, string defaultValue, ValidateInput validator)
            : this(title, message, defaultValue)
        {
            _validator = validator;
        }

        public InputBox( string title, string message, string defaultValue )
        {
            InitializeComponent();

            this.Text = title;
            this.lblMessage.Text = message;
            txtUserText.Text = defaultValue;
        }

        /// <summary>
        /// The text entered by the user.
        /// </summary>
        public string UserText
        {
            get { return txtUserText.Text; }
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            if (_validator == null || _validator(txtUserText.Text))
            {
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }
    }
}
